{extend name='../app/admin/view/common/block.html' /}

{block name="content"}
<div class="layui-btn-container">
    <button id="btnDeleteChecked" class="layui-btn layui-btn-sm layui-btn-danger" j-href="{:plugin_url('delete')}">
        <i class="layui-icon">&#xe640;</i>删除
    </button>
    <button class="layui-btn layui-btn-sm j-open"
            j-href="{:plugin_url('create')}"
            j-title="新增商品品牌"
            j-type="2"
            j-config='{"area":["80%","80%"],"anim":2}'
    >新增
    </button>
</div>
<div class="j-right">

</div>
    <table id="brands" lay-filter="brands"></table>
<script type="text/html" id="opera">
    <button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</button>
</script>
{/block}

{block name="script"}
<script>
    layui.use(['layer','table','jquery'],function(){
        var layer = layui.layer,
            table = layui.table,
            $ = layui.jquery;

        table.render({
            elem:'#brands',
            url:"{:plugin_url()}",
            page: true,
            height: 'full-200',
            toolbar: true,
            method:'post',
            cols: [[ //表头
                {type:'checkbox'}
                ,{field:'id',title:'ID',width:50}
                ,{field:'title',title:'品牌名称'}
                ,{field:'logo_path',title:'LOGO',templet:function(d){
                    if(d.logo_path){
                        return '<div><img src="'+d.logo_path+'" alt="" onclick="showImg(this)" width="100%"></div>';
                    }else{
                        return '-';
                    }
                }}
                ,{field:'status',title:'状态',templet:function(d){
                    if(d.status == 0){

                        return "<span class=\"layui-badge layui-bg-orange\">"+d.status_text+"</span>";
                    }else{

                        return "<span class=\"layui-badge layui-bg-green\">"+d.status_text+"</span>";
                    }
                }}
                ,{field:'sort',title:'排序',sort:true}
                ,{field:'createtime',title:'创建时间'}
                ,{title:'操作',templet:'#opera'}
                ]]
        });

        table.on('tool(brands)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定执行删除操作', function(index){
                    layer.close(index);
                    $.get('delete', {id:data.id},function(r){
                        if(r.code == 1){
                            showpopup(r.msg);
                            obj.del();
                        }else{
                            showpopup(r.msg);
                        }
                    },'json')
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type:2,
                    title:'编辑',
                    shadeClose:true,
                    area:['80%','80%'],
                    content:'update?id='+data.id
                })
            }
        });
    })
</script>
{/block}